/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view;

import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.Command;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BorderLayout;

/**
 *
 * @author Kvest
 */
public class PreOrderDetails extends Form implements ActionListener
{
    public static final int EMPTY_ID = 0;
    public static final int SIGN_ID = 1;
    public static final int BACK_ID = 2;
    public static final int UNSIGN_ID = 3;

    private Command empty;
    private Command sign;
    private Command unsign;
    private Command back;
    private FormAction listener;

    private TextArea text;

    public PreOrderDetails(FormAction listener)
    {
        super("Детали заказа");
        this.listener = listener;

        init();
    }

    private void init()
    {
        setLayout(new BorderLayout());

        addCommandListener(this);

        empty = new Command("", EMPTY_ID);
        back= new Command("Назад", BACK_ID);
        sign = new Command("Подписаться", SIGN_ID);
        unsign = new Command("Отписаться", UNSIGN_ID);

        text = new TextArea("", 1, 30);
        text.setAlignment(TextArea.LEFT);
        text.setEditable(false);

        addComponent(BorderLayout.NORTH, text);
    }

    public void actionPerformed(ActionEvent evt)
    {
        if (listener != null)
        {
            listener.commandAction(evt.getCommand().getId());
        }
    }

    public void setEmptyCommands(){
        removeAllCommands();
        addCommand(empty);
        addCommand(back);
    }
    
    public void setCommands(boolean driverIsSigned) {
        removeAllCommands();
        
        addCommand(empty);
        addCommand(back);
        if (driverIsSigned) {
            addCommand(unsign);
        } else {
            addCommand(sign);
        }
    }
    
    public void setText(String strDetails)
    {
        if (strDetails == null)
	{
            text.setText("Данные по заказу не были найдены");
	}
	else
        {
            text.setText(strDetails);
        }
    }
}
